package cn.myschool.web;

import cn.myschool.entity.Student;
import cn.myschool.pojo.Page;
import cn.myschool.service.StudentService;
import cn.myschool.util.StrUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Date;

/**
 * @author oldliu
 * @since 1.0
 */
//查询分页
 @WebServlet("/student")
public class StudentServlet extends HttpServlet {
    public static final  int PAGE_SIZE=20;
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse resp) throws ServletException, IOException {
        int pageNo= StrUtil.toInt(request.getParameter("pageNo"),1);
        String wechat= StrUtil.toStr(request.getParameter("wechat"));
        String qq=StrUtil.toStr(request.getParameter("qq"));
        String sname=StrUtil.toStr(request.getParameter("sname"));
        Date start=StrUtil.toDate(request.getParameter("dateStart"));
        Date end=StrUtil.toDate(request.getParameter("dateEnd"));
        Page<Student> page = StudentService.ME.search(wechat, qq, sname, start, end, pageNo);

        request.setAttribute("wechat",wechat);
        request.setAttribute("qq",qq);
        request.setAttribute("sname",sname);
        //
        request.setAttribute("start",start);
        request.setAttribute("end",end);
        //
        request.setAttribute("p",page);

        request.getRequestDispatcher("/WEB-INF/jsp/student/student.jsp").forward(request,resp);
    }
}
